/* 
 *  Syntelos XB
 *  Copyright (C) 2006 John Pritchard.
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License as
 *  published by the Free Software Foundation; either version 2 of
 *  the License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
 *  02111-1307 USA
 */

package syntelos.xb;

/** 
 * 
 * 
 * @author jdp
 */
public class Name 
    extends Base
{
    public final static syntelos.iou.dom.Name NAME = new syntelos.iou.dom.impl.Name(ELEMENT_NODE,"http://www.syntelos.org/xb","xb:name");

    public Name(org.w3c.dom.Document doc, syntelos.iou.dom.Name name){
        super(doc,name);
    }
    public Name(org.w3c.dom.Document doc){
        this(doc,NAME);
    }
    public Name(){
        this(DOC_NIL);
    }

    public syntelos.iou.dom.Node decompile(){
        this.getNameConst();

        return this;
    }
    public syntelos.iou.dom.Node compile(){
        this.getNameConst();

        return this;
    }
    public CF.Constants.Utf8 getNameConst(){
        return (CF.Constants.Utf8)this.getChildData(IO.Data.CONST_UTF8,this);
    }
    public java.lang.String getNameConstString(){
        CF.Constants.Utf8 name = this.getNameConst();
        if (null != name)
            return name.getString();
        else
            throw new Error.State("Missing operand");
    }
    public int getName(){
        CF.Constants.Utf8 name = this.getNameConst();
        if (null != name)
            return name.getIndex();
        else
            throw new Error.State("Missing operand");
    }
    public void setName(int index){
        CF.Constants constants = this.getConstants();
        CF.Constants.Utf8 name = constants.getConstUtf8(index);
        this.setChildData(name,this);
    }
    public void setName(CF.Constants.Utf8 name){

        this.setChildData(name,this);
    }
    public void setName(String value){
        CF.Constants constants = this.getConstants();
        CF.Constants.Utf8 name = constants.constUtf8(value);
        this.setChildData(name,this);
    }
    public void readCF(IO.Uri src, CF.Reader reader)
        throws java.io.IOException
    {
        int name_index = reader.readUnsignedShort();
        this.setName(name_index);
    }
    public void writeCF(IO.Uri dst, CF.Writer writer)
        throws java.io.IOException
    {
        int name_index = this.getName();
        writer.writeShort(name_index);
    }
    public java.lang.String toString(){
        CF.Constants.Utf8 constant = this.getNameConst();
        if (null != constant)
            return constant.toString();
        else
            return this.getChildText();
    }
}
